package com.lff.mapper;

import com.lff.domain.Role;
import com.lff.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper {
    //根据id查角色
    @Select("select * from smbms_role where id=#{id}")
    Role findRoleById(Integer id);
    //查询所有角色列表
    /*
    private Long id;//角色id
    private String roleCode;//角色代号
    private String roleName;//角色名
    private User createdBy;//添加人
    private Date creationDate;//添加时间
    private User modifyBy;//修改人
    private Date modifyDate;//修改时间
     */
    @Select("select * from smbms_role")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(property = "roleCode",column = "roleCode"),
            @Result(property = "roleName",column = "roleName"),
            @Result(property = "creationDate",column = "creationDate"),
            @Result(property = "modifyDate",column = "modifyDate"),
            @Result(property = "createdBy",
                    javaType = User.class,
                    column = "createdBy",
                    one = @One(select = "com.lff.mapper.UserMapper.findById")
            ),
            @Result(property = "modifyBy",
                    javaType = User.class,
                    column = "modifyBy",
                    one = @One(select = "com.lff.mapper.UserMapper.findById")
            )
    })
    List<Role> findRoleAll();
}
